<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工作日志列表')" />
    <style>
        table td{
            max-width: 285px;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>开发人：</p>
                                <input type="text" name="userId"/>
                            </li>
                            <li class="select-time">
                                <p>记录日期：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginMarkDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endMarkDate]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:record:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:record:remove')}]];
        var prefix = ctx + "system/record";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "工作日志",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'workId', 
                    title : 'ID',
                    visible: false
                },
                {
                    field : 'reqId', 
                    title : '所属需求',
                    formatter: function(value, row, index) {
                        var reqName;
                        if(value!=null){
                        $.ajax({
                            type:'post',
                            url: '/system/requirement/getReqname',
                            data:"reqId="+value,
                            async: false,
                            success: function(data){
                                var Requirement = JSON.parse(data);
                                reqName=Requirement.reqContent;
                            }
                        });
                    }
                    return reqName;
                }

                },
                {
                    field : 'workContent', 
                    title : '工作内容'
                },
                {
                    field : 'workDays', 
                    title : '使用工作量'
                },
                {
                    field : 'userId', 
                    title : '开发人',
                    formatter: function(value, row, index) {
                        var userName;
                        if(value!=null){
                            $.ajax({
                                type:'post',
                                url: '/system/user/getUsername',
                                data:"userId="+value,
                                async: false,
                                success: function(data){
                                    var user= JSON.parse(data);
                                    userName = user.userName;
                                }
                            });
                        }
                        return userName;
                    }
                },
                {
                    field : 'markDate', 
                    title : '记录日期',
                    formatter: function(value, row, index){
                        return changeDateFormat(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.workId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.workId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        //转换日期格式(时间戳转换为datetime格式)
        function changeDateFormat(cellval) {
            if (cellval != null) {
                var date = new Date(cellval);
                var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

                var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

                return month + "-" + currentDate + " " + hours + ":" + minutes;
            }
        }
    </script>
</body>
</html>